package com.zlf.sb.demo.design.chain;

import com.zlf.sb.demo.vo.ProductUpShelfReqDTO;
import org.apache.commons.lang3.StringUtils;
import org.springframework.stereotype.Component;

/**
 * 定义商品上架的责任链处理器
 */
@Component
public class ProductInfoNotNullChainFilter implements MerchantAdminAbstractChainHandler<ProductUpShelfReqDTO> {
    @Override
    public void handler(ProductUpShelfReqDTO requestParam) {
        if (StringUtils.isEmpty(requestParam.getProductName())) {
            throw new RuntimeException("商品名称不能为空！");
        }
        if (requestParam.getPrice() == null || requestParam.getPrice() <= 0) {
            throw new RuntimeException("商品价格必须大于0！");
        }
        System.out.println("商品信息非空校验通过");
    }

    @Override
    public int getOrder() {
        return 1;
    }

    @Override
    public String mark() {
        return ChainBizMarkEnum.MERCHANT_ADMIN_PRODUCT_UPSHELF_KEY.name();
    }
}

